package com.myflink.day03;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * @author Shelly An
 * @create 2020/9/18 10:20
 */
public class Transform_Union {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataStreamSource<Integer> num1DS = env.fromCollection(Arrays.asList(1, 2, 3, 4));
        DataStreamSource<Integer> num2DS = env.fromCollection(Arrays.asList(3, 2, 5, 8));

        //真正的合为一体  因此类型必须相同
        //可以连接多条流
        DataStream<Integer> unionDS = num1DS.union(num2DS);

        SingleOutputStreamOperator<Integer> result = unionDS.map(new MapFunction<Integer, Integer>() {
            @Override
            public Integer map(Integer value) throws Exception {
                return value * 10;
            }
        });

        result.print();

        env.execute();
    }
}
